package in.co.codedoc.sql.mapping;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;

import in.co.codedoc.sql.DBInputColumnMap;
import in.co.codedoc.sql.SQLStatement;

public class DoubleDoubleInputColumnMap 
	extends DBInputColumnMap
{
	public DoubleDoubleInputColumnMap(double v)
	{
		this.v = v;
		if((Double.MIN_VALUE == v) || (Long.MIN_VALUE == (long)v) || (Integer.MIN_VALUE == (long)v))
		{
			SetNull();
		}
	}

	@Override
	public void SetParameter(int index, PreparedStatement ps)
		throws SQLException
	{
		if(Logger.logger.isDebugEnabled())
		{
			if(index > 1)
			{
				SQLStatement.GetDebugStringBuffer().append(",");
			}
		}
		
		if(IsNull())
		{
			if(Logger.logger.isDebugEnabled())
			{
				SQLStatement.GetDebugStringBuffer().append("<NULL>");
			}
			
			ps.setNull(index,Types.DOUBLE);
		}
		else
		{
			if(Logger.logger.isDebugEnabled())
			{
				SQLStatement.GetDebugStringBuffer().append(v);
			}
			
			ps.setDouble(index, v);
		}
	}

	private double v;
}
